<?php include( "templates/include/header.php" );
  include( "templates/include/adminHeader.php" );?>
  
      <div id="adminHeader">
        <h2>Administation des galleries</h2>
        <p>Vous &ecirc;tes connect&eacute; en tant que <b><?php echo htmlspecialchars( $_SESSION['username']) ?></b>. <a href="admin.php?action=logout"?>Se D&eacute;connecter</a></p>
      </div>
 
      <h1>Toutes les Galleries</h1>
 
<?php if ( isset( $results['errorMessage'] ) ) { ?>
        <div class="errorMessage"><?php echo $results['errorMessage'] ?></div>
<?php } ?>
 
 
<?php if ( isset( $results['statusMessage'] ) ) { ?>
        <div class="statusMessage"><?php echo $results['statusMessage'] ?></div>
<?php } ?>

<?php 
  $count = 0;
  foreach ( $results['gallery'] as $gallery ) { ?>
  <div align="left" class="Box">
    <div class="BoxTitle" onclick="$('#box_<?php echo( $count );?>').toggle();" style="cursor:pointer">	
    <table width="100%">
      <tr>
        <td>
      		<font style="font-size:large;font-weight:bold;">
			      <?php echo( $gallery->title ); ?>
      		</font>
        </td>
        <td align="right">
          <a href="admin.php?action=editGallery&amp;galleryId=<?php echo $gallery->id?>">Editer</a>
        </td>
      </tr>
    </table>
	</div>

	<div id="box_<?php echo( $count );?>" class="BoxContent" style="display:none">
		<table align="center" cellpadding="2px" cellspacing="5px">
			<tr>
			</tr>
      <tr>
      <?php
        $list = array();
        $list = $gallery->getImages();
        foreach( $list['results'] as $image ) { ?>
          <td align="center" valign="bottom">
            <?php
            $tmp = explode( '/', $image['image']);
            echo( '<a href="admin.php?action=editImage&amp;id=' . $gallery->id . '&amp;imageId=' . $image['id'] .'&amp;origin=gallery"><img id="img_' . $image['id'] . ' class="thb {id:' . $image['id'] . ' }" style="cursor:pointer" width="150px" src="' . $image['image'] . '"> </a> </br>' ); ?>
  				</td>
        <?php } ?>
      </table>
      <center><a href="admin.php?action=uploadGalleryImage&amp;galleryId=<?php echo $gallery->id?>">Ajouter une image</a></center>
    </div>
  </div>
  </br>
<?php 
  $count++;
} ?>

      <p><?php echo $results['totalRows']?> gallerie<?php echo ( $results['totalRows'] != 1 ) ? 's' : '' ?> au total.</p>
 
      <p><a href="admin.php?action=newGallery">Ajouter une Gallerie</a></p>
 
<?php 
  include( "templates/include/adminFooter.php" );
  include( "templates/include/footer.php" ); ?>
